<?php
namespace app\decorate\model;
use app\BaseModel;
use think\facade\Db;



class AdminOfferRecord extends BaseModel
{
    //定义表名 报价记录表
    protected $name = 'longbing_card_decorate_offer_record';

    protected $append = [
      'house_wear'
    ];
    /**
     * @param $query
     * 查询范围
     */
    public function scopeStatus($query, $status){
        $query->where('status', '>', $status);
    }


    /**
     * User: chenniang
     * Date: 2019-10-25 16:13
     * @param $value
     * @param $data
     * @return void
     * descption:获取户型
     */
    public function getHouseWearAttr($value,$data){
        $model = new AdminHousewear();
        return $model->housewearTitleNo(['id'=>$data['hx_id']]);
    }



    /**
     * User: chenniang
     * Date: 2019-10-25 16:04
     * @param $value
     * @return false|string
     * descption:转换时间
     */
    public function getCreateTimeAttr($value){
        return date('Y-m-d H:i:s',$value);
    }

    /**
     * @param $dis
     * @return array
     * @throws \think\exception\DbException
     * 报价记录列表
     */
    public function offerList($dis,$page = 10,$whereor=[]){
        $data = $this->alias('a')
            ->leftJoin('longbing_card_user b','b.id=a.user_id')
            ->leftJoin('longbing_card_user_info c','c.fans_id=a.staff_id')
            ->where($dis)
            ->where(function ($query) use ($whereor){
                $query->whereOr($whereor);
            })
            ->field(['a.*','b.nickName','c.name as staff_name','b.avatarUrl'])
            ->group('a.id')
            ->order('a.id desc')
            ->paginate($page)
            ->toArray();
        return $data;
    }
    /**
     * @param $data
     * @return int|string
     * 添加报价记录
     */
    public function offerAdd($data){
        $data['create_time'] = time();
        $data['update_time'] = time();
        $data['status']      = 1;
        $res = $this->insert($data);
        return $res;
    }
    /**
     * @param $dis
     * @param $data
     * @return AdminCate
     * 编辑报价记录
     */
    public function offerUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }
    /**
     * @param $dis
     * @return AdminCate
     * 评论报价记录
     */
    public function offerInfo($dis){
        $data = $this->where($dis)->status(-1)->find();
        return !empty($data)?$data->toArray():$data;
    }

    /**
     * User: chenniang
     * Date: 2019-10-24 10:26
     * @param $dis
     * @return int
     * descption:报价条数
     */
    public function offerCount($dis){
       $data = $this->where($dis)->count();
       return $data;

    }




}